<!--_meta 作为公共模版分离出去-->
<!DOCTYPE HTML>
<html>
<head>
	<meta charset="utf-8">
	<meta name="renderer" content="webkit|ie-comp|ie-stand">
	<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
	<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1.0,maximum-scale=1.0,user-scalable=no" />
	<meta http-equiv="Cache-Control" content="no-siteapp" />
	<link rel="Bookmark" href="favicon.ico" >
	<link rel="Shortcut Icon" href="favicon.ico" />
	<!--[if lt IE 9]>
	<script type="text/javascript" src="lib/html5.js"></script>
	<script type="text/javascript" src="lib/respond.min.js"></script>
	<![endif]-->
	<link rel="stylesheet" type="text/css" href="static/h-ui/css/H-ui.min.css" />
	<link rel="stylesheet" type="text/css" href="static/h-ui.admin.pro/css/h-ui.admin.pro.css" />
	<link rel="stylesheet" type="text/css" href="lib/Hui-iconfont/1.0.9/iconfont.css" />
	<link rel="stylesheet" type="text/css" href="static/business/css/style.css" />
	<!--[if IE 6]>
	<script type="text/javascript" src="http://lib.h-ui.net/DD_belatedPNG_0.0.8a-min.js" ></script>
	<script>DD_belatedPNG.fix('*');</script><![endif]-->
	<!--/meta 作为公共模版分离出去-->

	<title>新增宿舍</title>
	<link href="lib/webuploader/0.1.5/webuploader.css" rel="stylesheet" type="text/css" />
</head>
<body>
	<article class="Hui-admin-page-container">
		<form class="form form-horizontal" id="form-article-add">
			<!-- 添加一个隐藏的输入框，从后台获取到宿舍信息后，将宿舍id传入其中，方便取用 -->
			<div><input type="text" id="dorId" name="dorId" hidden></div>

			<div class="row clearfix">
				<label class="form-label col-xs-4 col-sm-2"><span class="c-red"></span>位置：</label>
				<div class="form-controls col-xs-8 col-sm-9">
					<select id="apartmentName" name="apartmentName" class="select">
						<option value="-1">请选择宿舍位置</option>
					</select>
				</div>
			</div>
			<div class="row clearfix">
				<label class="form-label col-xs-4 col-sm-2"><span class="c-red"></span>楼栋：</label>
				<div class="form-controls col-xs-8 col-sm-9">
					<input type="text" class="input-text" autocomplete="off" id="floor" name="apartmentName">
				</div>
			</div>
			<div class="row clearfix">
				<label class="form-label col-xs-4 col-sm-2"><span class="c-red"></span>门牌号：</label>
				<div class="form-controls col-xs-8 col-sm-9">
					<input type="text" class="input-text" value="" id="doorNum" name="doorNum">
				</div>
			</div>
			<div class="row clearfix">
				<label class="form-label col-xs-4 col-sm-2"><span class="c-red"></span>最大住宿人数：</label>
				<div class="form-controls col-xs-8 col-sm-9">
					<input type="text" class="input-text" name="maxNum" id="maxNum">
				</div>
			</div>
			<div class="row clearfix">
				<label class="form-label col-xs-4 col-sm-2"><span class="c-red">*</span>宿舍类型：</label>
				<div class="form-controls col-xs-8 col-sm-9">
					<select id="type">
						<option value="2">二人间</option>
						<option value="4">四人间</option>
						<option value="6">六人间</option>
					</select>
				</div>
			</div>

			<div class="row clearfix">
				<div class="col-xs-8 col-sm-9 col-xs-offset-4 col-sm-offset-2">
					<button class="btn btn-primary radius" type="button" id="addDormitoryBtn"><i class="Hui-iconfont">&#xe632;</i> 添加</button>
					<button onClick="layer_close();" class="btn btn-default radius" type="button">&nbsp;&nbsp;取消&nbsp;&nbsp;</button>
				</div>
			</div>
		</form>
	</article>

	<!--_footer 作为公共模版分离出去-->
	<script type="text/javascript" src="lib/jquery/1.9.1/jquery.min.js"></script>
	<script type="text/javascript" src="lib/layer/3.1.1/layer.js"></script>
	<script type="text/javascript" src="static/h-ui/js/H-ui.js"></script>
	<script type="text/javascript" src="static/h-ui.admin.pro/js/h-ui.admin.pro.js"></script>
	<!--/_footer /作为公共模版分离出去-->

	
	<script type="text/javascript" src="lib/jquery.validation/1.14.0/jquery.validate.js"></script>
	<script type="text/javascript" src="lib/jquery.validation/1.14.0/validate-methods.js"></script>
	<script type="text/javascript" src="lib/jquery.validation/1.14.0/messages_zh.js"></script>
	<script type="text/javascript" src="static/business/js/main.js"></script>
	<script type="text/javascript">
	function layer_close(){
		var index = parent.layer.getFrameIndex(window.name);
		parent.layer.close(index);
	}
		$(function(){
			getMenu();

			// 宿舍位置信息
			$.ajax({
				method:"post",
				url:"dormitory?action=findDormitoryPosition",
				type:"json",
				success:function (result){
					console.log(result);
					var domitoryPositions = result.dormitoryPositions;
					// 将宿舍位置信息放入第一个select列表，id作为其value值
					for(var i = 0; i<domitoryPositions.length; i++){
						$("#apartmentName").append('<option value="'+ domitoryPositions[i].dorPosId +'">' + domitoryPositions[i].apartmentName + '</option>')
					}
				}
			});


			// 2. 点击添加按钮事件
			$("#addDormitoryBtn").click(function () {
				var dorPosId = $("#apartmentName").val();	// 寝室位置的id
			    var floor = $("#floor").val();	// 楼栋号
			    var doorNum = $("#doorNum").val();	// 门牌号
				var maxNum = $("#maxNum").val();	// 最大住宿人数，一开始剩余人数等于最大住宿人数
				var type = $("#type").val();	// 寝室类型
				if(dorPosId == -1){
					alert("请选择寝室类型");
					return;
				}
				if(floor.length<=0 || !$.isNumeric(floor)){
					alert("请输入正确的楼栋号");
					return;
				}
				if(doorNum.length<=0 || !$.isNumeric(doorNum)){
					alert("请输入正确的门牌号");
					return;
				}
				if(maxNum.length<=0 || !$.isNumeric(maxNum)){
					alert("请输入正确的最大住宿人数");
					return;
				}
				var data = {"dorPosId":dorPosId, "floor":floor, "doorNum":doorNum, "maxNum":maxNum, "type":type};

				$.ajax({
					method:"post",
					url:"dormitory?action=addDormitory",
					data:data,
					type:"json",
					success:function (result){
						console.log(result);
						if(result.code == 20002){
							alert(result.msg);
							location.href="/login.html";
						}else {
							alert(result.msg);
							location.href = "/dormitory-statistical.html";
						}
					}
				});
			})


			$(".textarea-picture").Huitextarealength({
				minlength: 10,
				maxlength: 500
			});
		});
	</script>
</body>
</html>
